package net.display;

import javax.servlet.http.HttpServletRequest;

import net.kernel.KFichefrais;
import net.ko.controller.KObjectController;
import net.ko.displays.KObjectDisplay;
import net.ko.http.views.KFieldControl;
import net.ko.kobject.KObject;
import net.ko.types.HtmlControlType;

public class Fichefrais extends KObjectDisplay {

	@Override
	public KFieldControl getControl(KObject ko, String memberName,
			KObjectController koc, HttpServletRequest request) {
		KFieldControl result= super.getControl(ko, memberName, koc, request);
		switch (memberName) {
		case "idVisiteur":
			result.setFieldType(HtmlControlType.khcReadOnlyList);
			break;
		case "idEtat":
			result.setFieldType(HtmlControlType.khcReadOnlyList);
			break;
		case "mois":
			result.setFieldType(HtmlControlType.khcReadOnlyList);
			break;
		case "dateModif":
			result.setFieldType(HtmlControlType.khcReadOnlyText);
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public String showInList(KObject ko, String memberName) {
		KFichefrais ff=(KFichefrais)ko;
		if("visiteur".equals(memberName)){
			String ligneColor="black;";
			if(ff.getMontantValide()>100)
				ligneColor="red;";
			return "<span style='color:"+ligneColor+"'>"+ff.getVisiteur()+"</span>";
		}
		return super.showInList(ko, memberName);
	}

	@Override
	public String getCaption(Class<? extends KObject> clazz) {
		return "Fiche de frais";
	}

	@Override
	public String getCaption(KObject ko, String memberName) {
		if("visiteur".equals(memberName))
			return "nouveau caption visiteur";
		return super.getCaption(ko, memberName);
	}
}